package logic.threads;

import java.util.ArrayList;

import logic.blocks.Block;
import logic.enemies.Enemy;
import logic.projectiles.FireBall;
import logic.pruebas.GamePanel;

/**
 * @author Unai
 * Hilo del disparo de bola de fuego
 *
 */
public class ShootFireBall implements Runnable{
	private float coorX;
	private float coorY;
	private boolean direction;
	private GamePanel panel;
	private ArrayList<Enemy> enemies;
	private ArrayList<Block> blocks;
	private int damage;
	private int delay;
	
	/**
	 * @param coorX
	 * @param coorY
	 * @param panel
	 * @param direction
	 * @param enemies
	 * @param blocks
	 * @param damage
	 * @param delay
	 */
	public ShootFireBall(float coorX, float coorY, GamePanel panel, boolean direction, ArrayList<Enemy> enemies, ArrayList<Block> blocks, int damage, int delay) {
		this.coorX = coorX;
		this.coorY = coorY;
		this.direction = direction;
		this.panel = panel;
		this.enemies = enemies;
		this.blocks = blocks;
		this.damage = damage;
		this.delay = delay;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		FireBall fireball = new FireBall(coorX, coorY, panel, "resources/fireball.gif", direction, damage);
		try {
			Thread.sleep(delay);
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		fireball.dibujar();
		while (!fireball.impacted) {
			fireball.update();
			for (Enemy e : enemies) {
				fireball.impact(e);
			}
			for (Block b : blocks) {
				fireball.impact(b);
			}
		}
		panel.remove(fireball);
		panel.updateUI();
		
	}

}
